package com.sskj.jgxt.repository;

import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.data.jpa.repository.Query;

import com.sskj.core.query.annotation.DynamicQuery;
import com.sskj.core.repository.GenericRepository;
import com.sskj.jgxt.jd.entity.YingBiGCBY;
import com.sskj.jgxt.param.RiZhiQueryParam;



public interface YingBiGCBYRepository extends GenericRepository<YingBiGCBY, String> {

	@Query(value = " from YingBiGCBY x where 1=1 "
			+ "<notEmpty name='keyword'> and (x.coding like '%${keyword}%' or x.eng.engName like '%${keyword}%') </notEmpty> "
			+ "<notEmpty name='userid'> and x.jlr=:userid </notEmpty> "
			+ "<notEmpty name='jlrq'> and x.createdTime >= :jlrq </notEmpty> order by  x.createdTime desc")
	@DynamicQuery
	Page<YingBiGCBY> findJLPage(RiZhiQueryParam queryParam,  Pageable pageable);
	
	@Query(value = " from YingBiGCBY x where 1=1 "
			+ "<notEmpty name='keyword'> and x.jcbw like '%${keyword}%' </notEmpty> "
			+ "<notEmpty name='engid'> and x.eng.oid =:engid </notEmpty> "			
			+ "<notEmpty name='userid'> and x.jlr=:userid </notEmpty> "
			+ "<notEmpty name='xcrq'> and x.jlrq >= :xcrq </notEmpty> order by  x.jlrq asc")
	@DynamicQuery
	Page<YingBiGCBY> findXCRQJLPage(RiZhiQueryParam queryParam,  Pageable pageable);
	
	@Query(value = " from YingBiGCBY x where 1=1 "
			+ "<notEmpty name='keyword'> and x.jcbw like '%${keyword}%' </notEmpty> "
			+ "<notEmpty name='engid'> and x.eng.oid =:engid </notEmpty> "								
			+ "<notEmpty name='userid'> and x.jlr=:userid </notEmpty>  order by  x.jlrq desc")
	@DynamicQuery
	Page<YingBiGCBY> findNameJLPage(RiZhiQueryParam queryParam,  Pageable pageable);	
	

	@Query(value = "from YingBiGCBY o where o.id=?1")
	YingBiGCBY findOneById(String spId);

	@Query(value = "select max(lower(o.coding)) from YingBiGCBY o where  1=1" + " and lower(o.coding) like lower(?1)"
			+ " and length(o.coding)=?2")
	String maxCode(String cdlike, Integer cdlen);

}
